package com.tanhua.bg.controller;


import com.tanhua.bg.service.LogService;
import com.tanhua.bg.vo.LogPageQueryParam;
import com.tanhua.bg.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@RequestMapping("manage")
public class LogController {

    @Autowired
    private LogService logService;


    //日志翻页-用户登录记录，/manage/logs，get     用户管理--用户详情--登录记录，管理员通过用户ID查询用户信息
    @GetMapping("logs")
    public ResponseEntity<PageResult> queryLogPage(@RequestHeader("Authorization") String token, LogPageQueryParam param) {



        try {
            //调用service根据用户请求和参数查询日志返回结果对象
            PageResult pageResult = this.logService.queryLogPage(token, param);
            //如果结果不为空，就返回结果
            if (null != pageResult) {
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询用户登录记录出错，token=" + token, e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


}
